<include file="Public/header" />
<include file="Public/menu" />

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            权限
            <small>管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 权限管理</a></li>
            <li class="active">编辑用户</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content"><div class="row"><div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">编辑用户</h3>

                <div class="box-tools">

                    <div class="btn-group pull-right" style="margin-right: 10px">
                        <a href="{:U('admin/rbac/user')}" class="btn btn-sm btn-default"><i class="fa fa-list"></i>&nbsp;用户列表</a>
                    </div>
                </div>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form action="{:U('admin/rbac/userEdit', ['id' => $user['id']])}" method="post" class="form-horizontal" id="form">
                <div class="box-body">
                    <?php
                    if ($user['type'] == 2) {
                ?>
                    <div class="form-group 1">
                        <label for="Continent" class="col-sm-2 control-label">角色</label>
                        <div class="col-sm-6">
                            <select class="form-control  select2-hidden-accessible" style="width: 100%;"
                                    id="Continent" name="role_id" tabindex="-1" aria-hidden="true">
                                <?php foreach($role as $v) { ?>
                                <option value="{$v['id']}" <?php echo $roleOne['id'] == $v['id'] ? 'selected' : ''; ?>>{$v['name']}</option>
                                <?php } ?>
                            </select>
                        </div>
                    </div>
                    <?php } ?>
                    <div class="form-group 1">
                        <label for="Name" class="col-sm-2 control-label">登陆用户名称</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="test" name="name" value="{$user['username']}" class="form-control" placeholder="登陆用户名称">
                                <input type="hidden" name="id" value="{$user['id']}">
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label for="Name" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="password" id="Name" name="password" value="" class="form-control" placeholder="不填为默认密码">
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <div class="col-sm-2">

                </div>
                    <div class="col-sm-6">

                        <div class="btn-group pull-left">
                            <button type="submit" class="btn btn-info pull-right">提交</button>
                        </div>
                    </div>

                </div>
                <!-- /.box-footer -->
            </form>
        </div>

    </div></div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />
<script data-exec-on-popstate>

    $(function () {

        $('.grid-select-all').change(function() {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('.batch-delete').on('click', function() {
            var selected = [];
            $('.grid-item:checked').each(function(){
                selected.push($(this).data('id'));
            });

            if (selected.length == 0) {
                return;
            }

            if(confirm("Are you sure to delete this item ?")) {
                $.post('/admin/auth/roles/' + selected.join(), {_method:'delete','_token':'ALpaP7hXZ6s2dnAdE02Z6mUSHPt8RkYbcDRp6rpw'}, function(data){
                    $.pjax.reload('#pjax-container');
                    noty({
                        text: "<strong>Succeeded!</strong>",
                        type:'success',
                        timeout: 1000
                    });
                });
            }
        });
        //表单验证
        $("#form").validate({
            rules: {
                name:{
                    required: true
                },
                password:{
                    required: true
                },
            },
            messages:{
                name: {
                    required: "请输入登陆用户名称",
                },
                password: {
                    required: "请输入密码",
                }
            },
            submitHandler: function(form){
                form.submit();   //提交表单
            }
        });
    });
</script>

